
#include <iostream>
#include <fstream>
#include "contacts.pb.h"


void PrintContacts(contacts::Contacts contacts)
{
    for(int i=0;i<contacts.contacts_size();i++)
    {
        std::cout<<"-----------------联系人"<<i+1<<"信息---------------------------"<<std::endl;
        const ::contacts::PeopleInfo& people=contacts.contacts(i);
        std::cout<<"联系人姓名："<<people.name()<<std::endl;
        std::cout<<"联系人年龄："<<people.age()<<std::endl;
        for(int j=0;j<people.phone_size();j++)
        {
            std::cout<<"联系人电话"<<j+1<<":";
            const ::contacts::PeopleInfo_Phone& phone=people.phone(j);
            std::cout<<phone.number()<<std::endl;
        }
    }
}
int main()
{
    contacts::Contacts contacts;
    std::fstream in("contacts.bin",std::ios::in|std::ios::binary);
    if(!contacts.ParseFromIstream(&in))
    {
        std::cerr<<"parse error"<<std::endl;
        in.close();
        return -1;
    }
    PrintContacts(contacts);
    in.close();

    return 0;
}